package dse;

import java.io.Serializable;

/**
 * A Data Object is an abstract representation of some logical data.  It only
 * describes the data's size and shares for storage.  Nothing else is known or 
 * required.  Well, we need an id for other uses ;)
 * 
 * @author Sam
 */
public class DataObject implements Comparable<DataObject>, Serializable
{
	private static final long serialVersionUID = 1L;
	private int id;
	private int size;
	private int shareCount;
	private int requiredShareCount;
	
	public DataObject (int id, int size, int shareCount, int requiredShareCount)
	{
		this.id = id;
		this.size = size;
		this.shareCount = shareCount;
		this.requiredShareCount = requiredShareCount;
	}

	public int id () { return this.id; }
	public int requiredShareCount () { return this.requiredShareCount; }
	public int shareCount () { return this.shareCount; }
	public void setShareCount(int sc) {shareCount = sc;}
	public int size () { return this.size; }	
	public int shareSize () { return this.size/this.requiredShareCount + 128; }
	
	
	public int compareTo (DataObject other) {
		return this.id - other.id;
	}
	
	
	/**
	 * Useful for debugging.
	 */
	@Override
	public String toString () {
		String res = String.format(
				"dobj#%d", 
				new Object [] {id}
				);
		return res;
	}
}
